﻿////////////////////////////////////////////////////////////////////////////////////////////////////
// file:	src\DirectoryManager.cs
//
// summary:	Implements the directory manager class
////////////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace PdfLucene
{
    public class DirectoryManager
    {
        
        public static bool CreateDirectory(string path)
        {
            DirectoryInfo directoryInfo = null;
            try
            {
                directoryInfo = Directory.CreateDirectory(path);
                           }
            catch (Exception)
            {
                
                throw;
            }
            return directoryInfo.Exists;

        }
        public static bool CheckDirectory(FileInfo fileInfo)
        {
            return CheckDirectory(fileInfo.FullName);
        }
        public static bool CheckDirectory(string path)
        {
            bool exists = false;
            try
            {
                if (!Directory.Exists(path))
                {
                    exists = CreateDirectory(path);
                }               
            }
            catch
            { 
            }
            return exists;
        }
        public static string[] ExploreDirectory(string path)
        {
            string[] files = null;
            try
            {
                CheckDirectory(path);
                files = Directory.GetFiles(path);
            }
            finally
            {

            }
            return files;
        }
        public static string[] GetPDFFromDirectory(string path)
        {
            return Directory.GetFiles(path, "*.pdf");
        }
    }
}
